package com.sun.service;

import com.sun.bean.Employee;
import com.sun.bean.EmployeeExample;
import com.sun.dao.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author sun
 */
@Service
public class EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    /**
     * 查询所有员工
     * @return 返回所有员工数据
     */
    public List<Employee> getAll(){
        return employeeMapper.selectByExampleWithDept(null);
    }

    /**
     * 保存员工
     * @return 返回所有员工数据
     */
    public int saveEmp(Employee employee){
        return employeeMapper.insertSelective(employee);
    }

    /**
     * 检查用户名是否可用
     * @param empName 员工姓名
     * @return true 代表可用
     */
    public boolean checkUser(String empName) {

        EmployeeExample employeeExample = new EmployeeExample();
        EmployeeExample.Criteria criteria = employeeExample.createCriteria();
        criteria.andEmpNameEqualTo(empName);
        long count=employeeMapper.countByExample(employeeExample);
        return count == 0;
    }
}
